/*
 * PhonemapAdapter.java
 */
package com.phonemap.service.server;

import java.util.Date;

import com.phonemap.service.server.jaxws.DeletePositions;
import com.phonemap.service.server.jaxws.DeletePositionsResponse;
import com.phonemap.service.server.jaxws.DeleteUser;
import com.phonemap.service.server.jaxws.DeleteUserResponse;
import com.phonemap.service.server.jaxws.GetHistory;
import com.phonemap.service.server.jaxws.GetHistoryResponse;
import com.phonemap.service.server.jaxws.GetPositions;
import com.phonemap.service.server.jaxws.GetPositionsResponse;
import com.phonemap.service.server.jaxws.GetUser;
import com.phonemap.service.server.jaxws.GetUserResponse;
import com.phonemap.service.server.jaxws.GetUsersByMeter;
import com.phonemap.service.server.jaxws.GetUsersByMeterResponse;
import com.phonemap.service.server.jaxws.GetUsersByName;
import com.phonemap.service.server.jaxws.GetUsersByNameResponse;
import com.phonemap.service.server.jaxws.InsertHistory;
import com.phonemap.service.server.jaxws.InsertHistoryResponse;
import com.phonemap.service.server.jaxws.InsertUser;
import com.phonemap.service.server.jaxws.InsertUserResponse;
import com.phonemap.service.server.jaxws.UpdatePosition;
import com.phonemap.service.server.jaxws.UpdatePositionResponse;
import com.phonemap.service.server.jaxws.UpdateUser;
import com.phonemap.service.server.jaxws.UpdateUserResponse;

// TODO: Auto-generated Javadoc
/**
 * The Class PhonemapAdapter.
 */
public class PhonemapAdapter {

	/** The phonemap api. */
	private PhonemapAPI phonemapAPI = new PhonemapAPI();

	/**
	 * Generate the Response Object corresponding to the argument in the request
	 * object.
	 *
	 * @param request the request
	 * @return returns response object
	 */

	public InsertUserResponse insertUser(InsertUser request) {
		long id = request.getId();
		String fullname = request.getFullname();
		String link = request.getLink();
		Date birthday = request.getBirthday();
		String interestedIn = request.getInterestedIn();
		String relationshipStatus = request.getRelationshipStatus();
		String gender = request.getGender();
		String email = request.getEmail();
		String timezone = request.getTimezone();
		String locale = request.getLocale();
		String verified = request.getVerified();
		String updatedTime = request.getUpdatedTime();
		String username = request.getUsername();
		float latitude = request.getLatitude();
		float longitude = request.getLongitude();
		Date locatedTime = request.getLocatedTime();
		String phone = request.getPhone();
		String userJSON = phonemapAPI.insertUser(id, fullname, link, birthday,
				interestedIn, relationshipStatus, gender, email, timezone,
				locale, verified, updatedTime, username, latitude, longitude,
				locatedTime, phone);

		InsertUserResponse response = new InsertUserResponse();
		response.setReturn(userJSON);
		return response;
	}

	/**
	 * Update user.
	 *
	 * @param request the request
	 * @return the update user response
	 */
	public UpdateUserResponse updateUser(UpdateUser request) {
		long id = request.getId();
		String fullname = request.getFullname();
		String link = request.getLink();
		Date birthday = request.getBirthday();
		String interestedIn = request.getInterestedIn();
		String relationshipStatus = request.getRelationshipStatus();
		String gender = request.getGender();
		String email = request.getEmail();
		String timezone = request.getTimezone();
		String locale = request.getLocale();
		String verified = request.getVerified();
		String updatedTime = request.getUpdatedTime();
		String username = request.getUsername();
		float latitude = request.getLatitude();
		float longitude = request.getLongitude();
		Date locatedTime = request.getLocatedTime();
		String phone = request.getPhone();
		String userJSON = phonemapAPI.updateUser(id, fullname, link, birthday,
				interestedIn, relationshipStatus, gender, email, timezone,
				locale, verified, updatedTime, username, latitude, longitude,
				locatedTime, phone);

		UpdateUserResponse response = new UpdateUserResponse();
		response.setReturn(userJSON);
		return response;
	}

	/**
	 * Update position.
	 *
	 * @param request the request
	 * @return the update position response
	 */
	public UpdatePositionResponse updatePosition(UpdatePosition request) {
		long id = request.getId();
		float latitude = request.getLatitude();
		float longitude = request.getLongitude();
		Date locatedTime = request.getLocatedTime();
		String positionJSON = phonemapAPI.updatePosition(id, latitude,
				longitude, locatedTime);
		UpdatePositionResponse response = new UpdatePositionResponse();
		response.setReturn(positionJSON);
		return response;
	}

	/**
	 * Gets the user.
	 *
	 * @param request the request
	 * @return the user
	 */
	public GetUserResponse getUser(GetUser request) {
		long id = request.getId();
		String userJSON = phonemapAPI.getUser(id);
		GetUserResponse response = new GetUserResponse();
		response.setReturn(userJSON);
		return response;
	}

	/**
	 * Delete user.
	 *
	 * @param request the request
	 * @return the delete user response
	 */
	public DeleteUserResponse deleteUser(DeleteUser request) {
		long id = request.getId();
		String userJSON = phonemapAPI.deleteUser(id);
		DeleteUserResponse response = new DeleteUserResponse();
		response.setReturn(userJSON);
		return response;
	}

	/**
	 * Delete positions.
	 *
	 * @param request the request
	 * @return the delete positions response
	 */
	public DeletePositionsResponse deletePositions(DeletePositions request) {
		long userId = request.getUserId();
		long id = request.getId();
		String positionJSON = phonemapAPI.deletePositions(id, userId);
		DeletePositionsResponse response = new DeletePositionsResponse();
		response.setReturn(positionJSON);
		return response;
	}

	/**
	 * Gets the positions.
	 *
	 * @param request the request
	 * @return the positions
	 */
	public GetPositionsResponse getPositions(GetPositions request) {
		long userId = request.getUserId();
		String positionJSON = phonemapAPI.getPositions(userId);
		GetPositionsResponse response = new GetPositionsResponse();
		response.setReturn(positionJSON);
		return response;
	}

	/**
	 * Gets the users by name.
	 *
	 * @param request the request
	 * @return the users by name
	 */
	public GetUsersByNameResponse getUsersByName(GetUsersByName request) {
		String name = request.getName();
		int offset = request.getOffset();
		String userJSON = phonemapAPI.getUsersByName(name, offset);
		GetUsersByNameResponse response = new GetUsersByNameResponse();
		response.setReturn(userJSON);
		return response;
	}

	/**
	 * Gets the history.
	 *
	 * @param request the request
	 * @return the history
	 */
	public GetHistoryResponse getHistory(GetHistory request) {
		long userId = request.getUserId();
		int offset = request.getOffset();
		int days = request.getDays();
		String userJSON = phonemapAPI.getHistory(userId, days, offset);
		GetHistoryResponse response = new GetHistoryResponse();
		response.setReturn(userJSON);
		return response;
	}
	
	/**
	 * Gets the users by meter.
	 *
	 * @param request the request
	 * @return the users by meter
	 */
	public GetUsersByMeterResponse getUsersByMeter(GetUsersByMeter request) {
		float latitude = request.getLatitude();
		float longitude = request.getLongitude();
		int meters = request.getMeters();
		int offset = request.getOffset();
		String userJSON = phonemapAPI.getUsersByMeter(latitude, longitude, meters, offset);
		GetUsersByMeterResponse response = new GetUsersByMeterResponse();
		response.setReturn(userJSON);
		return response;
	}
	
	/**
	 * Insert history.
	 *
	 * @param request the request
	 * @return the insert history response
	 */
	public InsertHistoryResponse insertHistory(InsertHistory request) {
		String json = request.getPostionsJSON();
		String userJSON = phonemapAPI.insertHistory(json);
		InsertHistoryResponse response = new InsertHistoryResponse();
		response.setReturn(userJSON);
		return response;
	}
}
